<template>
  <slot :name="`form-${props.component.dataIndex}`" v-bind="props.component">
    <a-link
      :disabled="props.component.disabled"
      :hoverable="props.component.hoverable"
      :href="props.component.href"
      :loading="props.component.loading"
      :status="props.component.status"
      @click="rv('onClick')"
    >
      <template v-if="props.component.icon" #icon>
        <component :is="props.component.icon" />
      </template>
      {{ props.component.title ?? "link" }}
    </a-link>
  </slot>
</template>

<script setup>
import { runEvent } from "@/components/MaForm/types/event";

const props = defineProps({
  component: Object
});

const formModel = inject("formModel");
const getColumnService = inject("getColumnService");
const columns = inject("columns");
const rv = async (ev, value = undefined) =>
  await runEvent(
    props.component,
    ev,
    {
      formModel,
      getColumnService,
      columns
    },
    value
  );

rv("onCreated");
onMounted(() => rv("onMounted"));
</script>
